package lxs.swift.tool.http;

import com.alibaba.fastjson2.JSON;

public class JsonPoster extends KVSender {

    public JsonPoster(Config config) {
        super(config, "{", ",", "}");
        config.header("Content-Type", "application/json");
        super.open();
    }

    @Override
    public byte[] toBytes(String key, Object value) {
        if (key == null || key.isEmpty() || value == null) return new byte[0];
        key = key.replace("\"", "\\\"");
        String item = "\"" + key + "\":" + JSON.toJSONString(value);
        return item.getBytes(config.charset);
    }


}
